package com.xiao.usercenter.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2WebMvc;

import java.util.ArrayList;

@Configuration
@EnableSwagger2WebMvc //开启swagger2,若启动类上添加了该注解，则配置类可以不添加
public class SwaggerConfig {
    // 创建swagger bean
    @Bean
    public Docket docket() {

        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo())
                .select()
                // 这里要标注控制器的位置
                .apis(RequestHandlerSelectors.basePackage("com.xiao.usercenter.controller"))
                .paths(PathSelectors.any())
                .build();
    }

    /**
     * api 信息
     * @return
     */
    // swagger文档信息
    public ApiInfo apiInfo() {

        return new ApiInfoBuilder()
                .title("用户中心")
                .description("用户中心接口文档")
                .version("1.0")
                .build();
    }
}
